#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int ans = 0, f = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        ans = (ans << 3) + (ans << 1) + c - 48, c = getchar();
    return f ? -ans : ans;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(48 + x % 10);
}
const int N = 3e5 + 5;
int n, m, l[N], r[N];
signed main()
{
    freopen("study.in", "r", stdin);
    freopen("study.out", "w", stdout);
    n = read(), m = read();
    for (int i = 1; i < n; ++i)
        l[i] = read(), r[i] = read() - 1;
    while (m--)
        if (read() == 1)
        {
            int i = read();
            l[i] = read(), r[i] = read() - 1;
        }
        else
        {
            int a = read(), b = read(), c = read(), d = read(), ans = 0;
            if (a <= c)
                for (int i = a; i < c; ++i, ++b)
                    b = max(b, l[i]),
                    ans += max(b - r[i], 0ll),
                    b = min(b, r[i]);
            else
                for (int i = a - 1; i >= c; --i, ++b)
                    b = max(b, l[i]),
                    ans += max(b - r[i], 0ll),
                    b = min(b, r[i]);
            ans += max(b - d, 0ll);
            write(ans), putchar('\n');
        }
    return 0;
}